FROM ubuntu:22.04

LABEL maintainer="Taylor Otwell"

ARG WWWGROUP
ARG NODE_VERSION=16
ARG POSTGRES_VERSION=14

WORKDIR /var/www/html

ENV DEBIAN_FRONTEND noninteractive
ENV TZ=UTC

RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

RUN apt-get update
RUN apt-get install -y gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2
#RUN apt-get install -y gnupg  \
#    && mkdir -p ~/.gnupg \
#    && chmod 600 ~/.gnupg \
#    && echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf \
#    && apt-key adv --homedir ~/.gnupg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 0x14AA40EC0831756756D7F66C4F4EA0AAE5267A6C \
#    && echo "deb https://ppa.launchpadcontent.net/ondrej/php/ubuntu impish main" > /etc/apt/sources.list.d/ppa_ondrej_php.list \
RUN apt-get install -y php8.1-cli php8.1-dev
RUN apt-get install -y php8.1-pgsql php8.1-sqlite3 php8.1-gd
RUN apt-get install -y php8.1-curl
RUN apt-get install -y php8.1-imap php8.1-mysql php8.1-mbstring
RUN apt-get install -y php8.1-xml php8.1-zip php8.1-bcmath php8.1-soap
RUN apt-get install -y php8.1-intl php8.1-readline
RUN apt-get install -y php8.1-ldap
RUN apt-get install -y php8.1-msgpack php8.1-igbinary php8.1-redis
RUN apt-get install -y php8.1-memcached php8.1-pcov
RUN php -r "readfile('https://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \
    && curl -sL https://deb.nodesource.com/setup_$NODE_VERSION.x | bash - \
    && apt-get install -y nodejs \
    && npm install -g npm \
#    && curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
#    && echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list \
#    && echo "deb http://apt.postgresql.org/pub/repos/apt impish-pgdg main" > /etc/apt/sources.list.d/pgdg.list \
#    && curl --silent -o - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
#    && apt-get update \
#    && apt-get install -y yarn \
    && apt-get install -y mysql-client
#    && apt-get install -y postgresql-client \
RUN apt-get install -y libgmp-dev php8.1-gmp
RUN apt-get -y autoremove \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN setcap "cap_net_bind_service=+ep" /usr/bin/php8.1

RUN groupadd --force -g $WWWGROUP sail
RUN useradd -ms /bin/bash --no-user-group -g $WWWGROUP -u 1337 sail

COPY start-container /usr/local/bin/start-container
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY php.ini /etc/php/8.1/cli/conf.d/99-sail.ini
RUN chmod +x /usr/local/bin/start-container

EXPOSE 8000

ENTRYPOINT ["start-container"]
